//################################################################################################################################//
//##                                                                                                                            ##//
//## This Page is implement for View Doctor Blogs behalf on Doctor Id                                                           ##//
//##                                                                                                                            ##//
//## Author   : Manish Prajapati                                                                                                ##//
//## Dated    : 20-03-2006                                                                                                      ##//
//##                                                                                                                            ##//
//################################################################################################################################//
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SiteManager;
public partial class Doctor_doctorForMessage : System.Web.UI.Page
{
    // creating an instance of manager class
    Manager manager = new Manager(true,"ConnectionString");
    int DoctorId = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["id"] != null)
        {
            try
            {
                DoctorId = Convert.ToInt32(Request.QueryString["id"]);
                PostMessage1.TopicId = DoctorId;//set blogid value in TopicId property
            }
            catch { }
        }
        if (!Page.IsPostBack)
        {
            BindDoctorBlog();
        }
        BindDoctorBlog();
    }
    /// <summary>
    /// Call BindDoctorBlog() function after load the page 
    /// </summary>
    /// <param name="writer"></param>
    protected override void Render(HtmlTextWriter writer)
    {
        if (Manager.GetPostBackControl(Page) == "btnSubmit")
        {
            BindDoctorBlog();
        }
        base.Render(writer);
    }
    /// <summary>
    /// Bind Grid behalf Doctor ID
    /// </summary>
    protected void BindDoctorBlog()
    {
        //Show doctor name and his/her email id in Label
        string SQLBlog = "SELECT (FName+' '+MName+' '+LName) AS Name FROM tbl_Doctors WHERE id = " + DoctorId;
        DataSet dsShowBlog = manager.ExecuteQuery(SQLBlog, "tbl_Topics");
        if (dsShowBlog.Tables[0].Rows.Count > 0)
        {
            lblBlogName.Text = dsShowBlog.Tables[0].Rows[0][0].ToString();
            lblDoctorName.Text = dsShowBlog.Tables[0].Rows[0][0].ToString();
        }
        //Show Doctor poat message in GridView
        //Server Side Validation 
//        string SQL = @"SELECT tbl_doctorMessage.Description AS msgDescription,tbl_doctorMessage.DateAdded AS msgDate,
//                    case usertype when 1 then (SELECT firstname +' '+lastname from tbl_admin WHERE adminid=tbl_doctorMessage.userid) 
//                    when 3 then (SELECT nickname from tbl_users WHERE id=tbl_doctorMessage.userid)
//                    end AS postedName FROM  tbl_doctorMessage WHERE tbl_doctorMessage.DoctorId = " + DoctorId + "Order By  tbl_doctorMessage.DateAdded DESC";

        string SQL = @"SELECT tbl_doctorMessage.Description AS msgDescription,tbl_doctorMessage.DateAdded AS msgDate,
                    case usertype when 1 then (SELECT 'Admin') 
                    when 3 then (SELECT nickname from tbl_users WHERE id=tbl_doctorMessage.userid)
                    when 2 then (SELECT FName from tbl_dentists WHERE id=tbl_doctorMessage.userid)
                    when 4 then (SELECT FName from tbl_doctors WHERE id=tbl_doctorMessage.userid) 
                    end AS postedName FROM  tbl_doctorMessage WHERE tbl_doctorMessage.DoctorId = " + DoctorId + "Order By  tbl_doctorMessage.DateAdded DESC";

        DataSet ds = manager.ExecuteQuery(SQL, "tbl_doctorMessage");
        if (ds.Tables[0].Rows.Count > 0)
        {
            grdDoctorBlog.DataSource = ds.Tables[0];
            grdDoctorBlog.DataBind();
            lblerr.Visible = false;
        }
        else
        {
            lblerr.Text = "<font color=red><b>No message posted currently !!!</b></font>";
            lblerr.Visible = true;
        }
    }
    
}
